package com.example.picassodemo01.views;


import android.os.Environment;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.picassodemo01.R;
import com.example.picassodemo01.base.BaseActivity;
import com.example.picassodemo01.contract.HeroContract;
import com.example.picassodemo01.entity.HeroEntity;
import com.example.picassodemo01.presenter.HeroPresenter;
import com.example.picassodemo01.utils.LogUtils;


public class HeroActivity extends BaseActivity
        implements HeroContract.IHeroView, View.OnClickListener {

    private EditText mEdit;
    private Button mButton;
    private TextView mText;
    private ImageView mImage;
    private ImageView mImage2;
    private HeroContract.IHeroPresenter mPresenter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_hero;
    }

    @Override
    public void init() {
        mEdit = findViewById(R.id.edit);
        mButton = findViewById(R.id.button);
        mText = findViewById(R.id.text);
        mImage = findViewById(R.id.image);
        mImage2 = findViewById(R.id.image2);
        mButton.setOnClickListener(this);
        mPresenter = new HeroPresenter(this);
    }

    @Override
    public void showData(HeroEntity hero) {
        if (hero != null && hero.getData() != null) {
            LogUtils.d("asdf", "hero : " + hero.getData().getName());
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("名字 : ").append(hero.getData().getName()).append("\n");
            stringBuilder.append("职业 : ").append(hero.getData().getOccupation()).append("\n");
            stringBuilder.append("皮肤 : ").append(hero.getData().getSkin_name()).append("\n");
            stringBuilder.append("介绍 : ").append(hero.getData().getFace_img()).append("\n");
            mText.setText(stringBuilder.toString());
            //Picasso.get().load(R.mipmap.error).into(mImage);
            //Picasso.get().load("file:///android_asset/apple.png").into(mImage);
            String path = Environment.getExternalStorageDirectory() + "/Pictures/1758990909779.png";
            //Picasso.get().load(new File(path)).into(mImage);//需要权限
            //Picasso.get().load("https://kkimgs.yisou.com/ims?kt=url&at=ori&key=aHR0cDovL2ltZzQuc3VjYWlzdWNhaS5jb20vMDQvNDcvMDQxNDc3ODRfMS5qcGc=&sign=yx:4kKHcFYTkTNtGyJxy-O09lnyyo0=&tv=0_0").into(mImage);

        } else {
            showToast("未查到数据，请输入正确信息！");
        }
    }

    @Override
    public void onHttpLoading(boolean loading) {

    }

    @Override
    public void onHttpFail(String... msg) {

    }

    @Override
    public void onHttpTimeout() {

    }

    @Override
    public void onHttpTokenExpiration() {

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.button) {
            String heroName = mEdit.getText().toString();
            if (!TextUtils.isEmpty(heroName)) {
                mPresenter.getData(heroName);
            }
        }
    }
}